import 'package:fluent_ui/fluent_ui.dart';
import 'package:jm_flutter/jm_flutter.dart';
import '../my_text.dart';

enum MyButtonType { text, filled,outlined }

class MyButton extends StatelessWidget {
  final MyButtonType type;
  final VoidCallback onPressed;
  final Widget? child;
  final String text;
  final Color? textColor;
  final double textSize;
  final Color color;
  final bool isEnable;
  final bool? i18n;

  Widget? _text;

  MyButton({
    Key? key,
    this.type = MyButtonType.text,
    required this.onPressed,
    this.child,
    this.text = "",
    this.textColor,
    this.textSize = 14,
    this.color = Colors.transparent,
    this.isEnable = true,
    this.i18n,
  }) : super(key: key) {
    _text = MyText(
      text,
      color: type == MyButtonType.filled ? Colors.white :textColor,
      i18n: i18n,
      size: textSize,
      weight: type == MyButtonType.filled ? FontWeight.bold : FontWeight.normal,
    );
  }

  MyButton.outlined({
    Key? key,
    this.type = MyButtonType.outlined,
    required this.onPressed,
    this.child,
    this.text = "",
    this.textColor,
    this.textSize = 14,
    this.color = Colors.transparent,
    this.isEnable = true,
    this.i18n,
  }) : super(key: key) {
    _text = MyText(
      text,
      color: textColor,
      i18n: i18n,
      size: textSize,
      weight: FontWeight.bold,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Opacity(
      opacity: isEnable ? 1.0 : 0.5,
      child: _widget(),
    );
  }

  void _onTap() {
    onPressed();
  }

  Widget _widget() {
    switch (type) {
      case MyButtonType.text:
        return Button(
          onPressed: isEnable ? _onTap : null,
          child: child ?? _text!,
          // style: ButtonStyle(
          //   //backgroundColor: MaterialStateProperty.all<Color>(color),
          //   //overlayColor: MaterialStateProperty.all<Color>(Colors.red)
          // ),
        );
      case MyButtonType.outlined:
        return OutlinedButton(
          onPressed: isEnable ? _onTap : null,
          child: child ?? Text(text),
        );
      case MyButtonType.filled:
        return FilledButton(
          onPressed: isEnable ? _onTap : null,
          child: child ?? _text!,
          // style: ButtonStyle(
          //   //backgroundColor: MaterialStateProperty.all<Color>(color),
          //   //overlayColor: MaterialStateProperty.all<Color>(Colors.red)
          // ),
        );
    }
  }
}
